package cn.mafangui.hotel.controller.worker;

import cn.mafangui.hotel.entity.GarageAccessRecord;
import cn.mafangui.hotel.exception.HotelException;
import cn.mafangui.hotel.req.PageQueryReq;
import cn.mafangui.hotel.req.ParkingInReq;
import cn.mafangui.hotel.response.AjaxResult;
import cn.mafangui.hotel.response.ResponseTool;
import cn.mafangui.hotel.service.GarageAccessRecordService;
import cn.mafangui.hotel.service.GarageStallService;
import cn.mafangui.hotel.utils.PropInfoConstant;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: kalpa
 * @date: 2022/3/18
 * @version: 1.0
 * Description: 停车管理
 */
@Api(tags = "操作员-停车管理")
@RestController
@RequestMapping(value = "/op/parking")
public class OpParkingController {
    @Autowired
    GarageAccessRecordService garageAccessRecordService;


    @ApiOperation("停车登记")
    @PostMapping("/in")
    public AjaxResult in(ParkingInReq req) throws HotelException {
        garageAccessRecordService.in(req);
        return ResponseTool.success(PropInfoConstant.PARKING_IN_SUCCESS);
    }

    @ApiOperation("车辆出库")
    @PostMapping("/out")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="id", value = "车位的id")
    })
    public AjaxResult out(@RequestParam("id") Integer id) throws HotelException {
        garageAccessRecordService.out(id);
        return ResponseTool.success(PropInfoConstant.PARKING_OUT_SUCCESS);
    }

    @ApiOperation(value = "分页查询所有的车库停车纪录", notes = "根据停车时间逆序返回")
    @GetMapping("/getAllByPage")
    public AjaxResult getAllByPage(PageQueryReq req){
        List<GarageAccessRecord> allByPage = garageAccessRecordService.getAllByPage(req);
        PageInfo pageInfo = new PageInfo(allByPage);
        return ResponseTool.success(pageInfo);
    }


}
